var role = 1;
document.getElementById('loginForm').addEventListener('submit', function(e) {
    e.preventDefault();
    const account = document.getElementById('username').value;
    const password = document.getElementById('password').value;
    // 简单的验证
    if (account === '' || password === '') {
        alert('请输入学号和密码');
        return;
    }
    // 显示加载效果
    const loginBtn = document.querySelector('.btn-login');
    const originalText = loginBtn.innerHTML;
    loginBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> 登录中...';
    loginBtn.disabled = true;

    // 模拟登录请求
    setTimeout(() => {

        $.ajax({
            url: "/teacher/login",  // 地址
            type: "POST",  // 修改为 POST 请求
            data:{
                "workNumber": account,
                "password": password
            }, success: function (value) {
                if(value.code==200){
                    console.log(value)
                    $.cookie("teacher",value.data.id)
                    $.cookie("teacherName",value.data.name)
                    $.cookie("role",role)
                    $.cookie("teachericon",value.data.icon)
                    // 模拟登录成功
                    loginBtn.innerHTML = '<i class="fas fa-check"></i> 登录成功!';
                    loginBtn.style.background = 'linear-gradient(to right, #34a853, #2d9248)';
                    // 跳转到主页面
                    setTimeout(() => {
                        window.location.href="TeacherEnd";
                    }, 1000);
                }else{
                    alert("登陆失败")
                }
            }, error: function (xhr, status, error) {
                console.error("Error:", error);
                alert("登录请求失败，请重试。");
            }
        });

    }, 1500);
});